# -*- coding:utf-8 -*-
# @Time : 2020/7/21 8:45
# @Author : Administrator
# @File : task.py
# @Software: PyCharm
# @Motto: good good study,day day up

from celery import task
from django.core.mail import send_mail
from .models import Order


@task
def order_created(order_id):
    """
    当一个订单创建完成后发送邮件通知给用户
    """
    order = Order.objects.get(id=order_id)
    subject = f'Order {order.id}'
    message = f'Dear {order.first_name},\n\nYou have successfully placed an order. Your order id is {order_id}.'
    mail_sent = send_mail(subject, message, '172667104@qq.com', [order.email])
    print(mail_sent, type(mail_sent))
    return mail_sent
